<template>
  <div class="user-container">
    <div class="info-box">
      <van-image
        round
        fit="cover"
        width="64"
        height="64"
        :src="userInfo.photo"
      />
      <h2>
        {{userInfo.name}}<br /><van-tag color="#ccc" text-color="#fff">{{userInfo.birthday}}</van-tag>
      </h2>
    </div>
    <van-row>
      <van-col span="8">
        <van-icon name="newspaper-o" color="#1989fa" /><br />
        <span>我的作品</span>
      </van-col>
      <van-col span="8">
        <van-icon name="newspaper-o" color="#1989fa" /><br />
        <span>我的作品</span>
      </van-col>
      <van-col span="8">
        <van-icon name="newspaper-o" color="#1989fa" /><br />
        <span>我的作品</span>
      </van-col>
    </van-row>

    <van-cell-group>
      <van-cell title="编辑资料" icon="edit"  is-link @click="$router.push({path:'/edit'})"/>
      <van-cell title="小智同学" icon="chat-o"  is-link/>
      <van-cell title="系统设置" icon="setting-o"  is-link/>
      <van-cell title="退出登录" icon="warning-o"  is-link @click="logout"/>
    </van-cell-group>
  </div>
</template>

<script>
import {getUserInfo} from './user.js'
import {removeToken} from '../../utils/token.js'
export default {
  name: 'user',
  data(){
    return{
      userInfo:{}
    }
  },
  methods:{
    logout(){
      this.$dialog.confirm({
        title:'提示',
        message:"确定要退出登录吗？"
      })
      .then(()=>{
        // 删除token
        removeToken();
        this.userInfo={};
        this.$router.push({path:'/login'})
      })
      .catch(()=>{
        console.log('取消');
      }) 
    }
  },
  created(){
    getUserInfo()
    .then(res=>{
      console.log(res);
      this.userInfo=res.data.data;
      this.$store.commit('updateUserInfo',res.data.data)
    })
  }
}
</script>

<style lang="less">
.user-container {
  .info-box {
    height: 100px;
    background-color: rgb(154, 154, 189);
    display: flex;
    align-items: center;
  }
  .van-image {
    padding: 0 10px;
  }
  h2 {
    font-size: 18px;
    color: #fff;
    font-weight: normal;
  }

  .van-row {
    margin-top: 10px;
    text-align: center;
    span {
      font-size: 12px;
      display: block;
      margin-bottom: 15px;
    }
  }
}
</style>
